package com.yjd.comm.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.yjd.comm.org.model.ServiceTypeDto;
import com.yjd.comm.system.model.SysParamModel;
import com.yjd.comm.system.util.SysParamUtil;
import com.yjd.comm.vo.Constant;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yjd-wap on 2017/7/19.
 */
public class TypeShowUtils {

   public static Logger logger = Logger.getLogger(TypeShowUtils.class);

    /**
     * 获取机构类型列表
     * @return
     * @throws Exception
     */
    public static Map<Integer, String> getOrgType() {
        Map<Integer, String> orgType = new HashMap<Integer, String>();

        try {
            SysParamModel sysParam = SysParamUtil.getSysParamModel(Constant.SysParamKeyEnum.ORGANIZATION_TYPE);
            if(null != sysParam){
                orgType = JSON.parseObject(sysParam.getParam_value(), new TypeReference<Map<Integer, String>>(){});
            }
        } catch (Exception e) {
            logger.error("获取机构类型列表失败，错误信息："+e);
        }

        return orgType;
    }

    /**
     * 获取机构显示类型
     * @param type
     * @return
     * @throws Exception
     */
    public static String getOrgTypeShow(Integer type) {
        String show = getOrgType().get(type);
        if(StringUtil.isEmpty(show) ){
            return "其他";
        }
        return show;
    }

    /**
     * 获取医生职位列表
     * @return
     * @throws Exception
     */
    public static Map<Integer, String> getDoctorTitle() {
        Map<Integer, String> title = new HashMap<Integer, String>();

        try {
            SysParamModel sysParam = SysParamUtil.getSysParamModel(Constant.SysParamKeyEnum.DOCTORTITL);
            if(null != sysParam){
                title = JSON.parseObject(sysParam.getParam_value(), new TypeReference<Map<Integer, String>>(){});
            }
        } catch (Exception e) {
            logger.error("获取医生职位列表失败，错误信息："+e);
        }

        return title;
    }

    /**
     * 获取医生职位显示类型
     * @param type
     * @return
     * @throws Exception
     */
    public static String getDoctorTitleShow(Integer type) {
        String show = getDoctorTitle().get(type);
        if(StringUtil.isEmpty(show) ){
            return "";
        }
        return show;
    }

    /**
     * 获取机构服务列表
     * @return
     * @throws Exception
     */
    public static Map<Integer, String> getServiceTypeMap() {
        Map<Integer, String> serviceType = new HashMap<Integer, String>();

        try {
            SysParamModel sysParam = SysParamUtil.getSysParamModel(Constant.SysParamKeyEnum.MFQ_SERVICE_TYP_LIST);
            if(null != sysParam){
                serviceType = JSON.parseObject(sysParam.getParam_value(), new TypeReference<Map<Integer, String>>(){});
            }
        } catch (Exception e) {
            logger.error("获取机构服务列表失败，错误信息："+e);
        }

        return serviceType;
    }

    /**
     * 获取机构服务列表
     * @return
     * @throws Exception
     */
    public static List<ServiceTypeDto> getServiceTypeList() {
        List serviceTypeList = new ArrayList<ServiceTypeDto>();
        Map<Integer, String> serviceType = getServiceTypeMap();
        Iterable<Integer> it = serviceType.keySet();
        for (Integer key :it){
            serviceTypeList.add(new ServiceTypeDto(key,serviceType.get(key)));
        }
        return serviceTypeList;
    }
}
